import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { promotionsStatusRender, couponTypeRender,} from "/@/views/cater/promotions/js/promotion.enums";

export const columns: BasicColumn[] = [
  { title: "状态", width: 65, dataIndex: "promotionStatus", align: "center", //fixed: "right",
    customRender: ({text, record}) => {
      return promotionsStatusRender(record);
    }
  },
  { title: "优惠券名称", dataIndex: "couponName", width: 140, align: "left", },
  { title: "优惠券类型", dataIndex: "couponType", width: 70, 
    customRender: ({text}) => {
      return couponTypeRender(text);
    }
  },
  { title: "面额/折扣", dataIndex: "price", width: 60,
    customRender: ({ text, record }) => {
      if (record.couponType == 'DISCOUNT') {
        return record.couponDiscount + " 折"
      } else if (record.couponType == 'PRICE') {
        return record.price + " 元"
      } else if (record.couponType == 'LARGESS') {
        return "赠送"
      } else {
        return text
      }
    },
  },
  { title: "每人限领", dataIndex: "couponLimitNum", width: 40 },
  { title: "发放数量", dataIndex: "publishNum", width: 55,
    customRender: ({ text, record }) => {
      return (record.publishNum === 0 ? "不限制" : record.publishNum)
    }
  },
  { title: "已领取", dataIndex: "receivedNum", width: 55 },
  { title: "已使用", dataIndex: "usedNum", width: 55, },
  { title: "活动时间", width: 200,
    customRender: ({ text, record }) => {
      if ( record.getType === "ACTIVITY" && record.rangeDayType === "DYNAMICTIME" ) {
        return "长期有效";
      } else if (record.startTime && record.endTime) {
        return record.startTime + " 至 " + record.endTime;
      }
    }
  },
];

export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  {label: '', field: 'id', component: 'Input', show: false},
  {
    label: '优惠券名称',
    field: 'couponName',
    component: 'Input',
    colProps: { span: 22 },
    required: true,
  },
  {
    label: '优惠券类型',
    field: 'couponType',
    component: 'JDictSelectTag',
    colProps: { span: 22 },
    required: true,
    defaultValue: 'DISCOUNT',
    componentProps: {
      dictCode: 'couponType', 
      placeholder: ' ', 
      getPopupContainer: () => document.body,
    },
  },
  {
    label: '折扣',
    field: 'couponDiscount',
    colProps: { span: 22 },
    component: 'InputNumber',
    componentProps: {
      max: 9,
      min: 1,
      step: 0.1
    },
    rules: [{required: true, type: 'string'}],
    ifShow: ({ values }) => { 
      return values.couponType == "DISCOUNT"
    }
  },
  {
    label: '面额',
    field: 'price',
    colProps: { span: 22 },
    component: 'InputNumber',
    componentProps: {
      min: 1
    },
    rules: [{required: true, type: 'string'}],
    ifShow: ({ values }) => { 
      return values.couponType == "PRICE" 
    }
  },
  {
    label: '发放数量',
    colProps: { span: 22 },
    field: 'publishNum',
    component: 'InputNumber',
    componentProps: {
      min: 1
    },
    required: true,
  },
  {
    label: '每人限领',
    colProps: { span: 22 },
    field: 'couponLimitNum',
    component: 'InputNumber',
    defaultValue: 1,
    componentProps: {
      min: 0
    },
  },
  {
    label: '开始时间',
    field: 'startTime',
    required: true,
    component: 'DatePicker',
    componentProps: {
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
  },
  {
    label: '结束时间',
    field: 'endTime',
    component: 'DatePicker',
    required: true,
    componentProps: {
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
  },
];